package com.qiaofang.repository;

import com.qiaofang.entity.Area;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AreaRepository extends JpaRepository<Area, Long> {

    @Query(value = "from Area t where t.parent is null order by t.id ASC")
    List<Area> listProvince();

    @Query(value = "from Area t where t.parent = :provinceId order by t.id ASC")
    List<Area> listCity(@Param(value = "provinceId") Long provinceId);

    @Query(value = "from Area t where t.parent = :cityId order by t.id ASC")
    List<Area> listZone(@Param(value = "cityId") Long cityId);
}
